//
//  YBSelectPeopleHeadView.m
//  GongXinDangJian
//
//  Created by apple on 17/11/30.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "YBSelectPeopleHeadView.h"

@interface YBSelectPeopleHeadView ()
@property (nonatomic , strong) UIImageView * openImageView;

@property (nonatomic , strong) UILabel * cellTitleLabel;

@property (nonatomic , strong) UIButton * selectButton;

@property (nonatomic , strong) UIButton * openButton;

@property (nonatomic , strong) UIImageView * selectImageView;
@end

@implementation YBSelectPeopleHeadView

-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self ybInitMyCell];
    }
    return self;
}


-(void)ybInitMyCell{
    [self.contentView addSubview:self.openImageView];
    [self.contentView addSubview:self.cellTitleLabel];
    [self.contentView addSubview:self.openButton];
    [self.contentView addSubview:self.selectImageView];
    [self.contentView addSubview:self.selectButton];
    UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(0, ItemHeight * 80 - 1, [UIScreen zj_screenWith], 1)];
    lineView.backgroundColor = [UIColor themeGrayColor];
    [self.contentView addSubview:lineView];
}


-(void)option_openButton:(UIButton *)sender{
    self.isOpen = !self.isOpen;
    if (self.delegate && [self.delegate respondsToSelector:@selector(viewDidClickWithSection:isOpen:)]) {
        [self.delegate viewDidClickWithSection:self.ybSection isOpen:self.isOpen];
    }
}


-(void)option_selectButton:(UIButton *)sender{
    self.viewSelected = !self.viewSelected;
    if (self.delegate && [self.delegate respondsToSelector:@selector(viewDidClickWithSection:viewSelected:)]) {
        [self.delegate viewDidClickWithSection:self.ybSection viewSelected:self.viewSelected];
    }
}

-(void)setIsOrg:(BOOL)isOrg
{
    _isOrg = isOrg;
    if (isOrg) {
        self.openImageView.hidden = YES;
        self.openButton.hidden = YES;
        self.cellTitleLabel.frame = CGRectMake(ItemWidth * 30, 0, [UIScreen zj_screenWith] - ItemWidth * 176, ItemHeight * 80);
    }
}


-(void)setModel:(YBSelectHeadModel *)model
{
    _model = model;
    self.isOpen = model.ISOPEN;
    self.viewSelected = model.ISALLSELECT;
    self.cellTitleLabel.text = [ToolClass returnNoNullStringWithString:model.NAME];
}


-(UIImageView *)openImageView
{
    if (!_openImageView) {
        _openImageView = [[UIImageView alloc]initWithFrame:CGRectMake(ItemWidth * 15, (ItemHeight * 80 - ItemWidth * 44) / 2, ItemWidth * 44, ItemWidth * 44)];
        _openImageView.image = [UIImage imageNamed:@"jiantou_r"];
    }
    return _openImageView;
}


-(UILabel *)cellTitleLabel
{
    if (!_cellTitleLabel) {
        _cellTitleLabel = [ToolClass creatLabelWithFrame:CGRectMake(ItemWidth * 74, 0, [UIScreen zj_screenWith] - ItemWidth * 176, ItemHeight * 80) font:16 textColor:[UIColor textBlackColor] text:@""];
    }
    return _cellTitleLabel;
}


-(UIButton *)selectButton
{
    if (!_selectButton) {
        _selectButton = [ToolClass createButtonWithFrame:CGRectMake([UIScreen zj_screenWith] - ItemWidth * 102, 0, ItemWidth * 102, ItemHeight * 80) text:@"" textColor:[UIColor whiteColor] imageName:@"" font:15];
        [_selectButton addTarget:self action:@selector(option_selectButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectButton;
}


-(UIImageView *)selectImageView
{
    if (!_selectImageView) {
        _selectImageView = [[UIImageView alloc]initWithFrame:CGRectMake([UIScreen zj_screenWith] - ItemHeight * 72, (ItemHeight * 80 - ItemWidth * 42) / 2, ItemWidth * 42, ItemWidth * 42)];
        _selectImageView.image = [UIImage imageNamed:@"list_select"];
    }
    return _selectImageView;
}


-(UIButton *)openButton
{
    if (!_openButton) {
        _openButton = [ToolClass createButtonWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith] - ItemWidth * 102 , ItemHeight * 80) text:@"" textColor:[UIColor whiteColor] imageName:@"" font:15];
        [_openButton addTarget:self action:@selector(option_openButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _openButton;
}

-(void)setIsOpen:(BOOL)isOpen
{
    _isOpen = isOpen;
    if (isOpen) {
        self.openImageView.image = [UIImage imageNamed:@"jiantou_d"];
    }
    else{
        self.openImageView.image = [UIImage imageNamed:@"jiantou_r"];
    }
}


-(void)setViewSelected:(BOOL)viewSelected
{
    _viewSelected = viewSelected;
    if (viewSelected) {
        self.selectImageView.image = [UIImage imageNamed:@"list_selected"];
    }
    else{
        self.selectImageView.image = [UIImage imageNamed:@"list_select"];
    }
}

@end
